#include "camera.h"

using namespace alice;

Camera* Camera::instance_ = nullptr;

void Camera::Update(double delta_time) {
  if (target_ != nullptr) {
    view_box_.x = target_->X - kWindowWidth / 2;
    view_box_.y = target_->Y - kWindowHeight;

    if (view_box_.x < 0) {
      view_box_.x = 0;
    }
    if (view_box_.y < 0) {
      view_box_.y = 0;
    }

    if (view_box_.x > 2*kWindowWidth - view_box_.w) {
      view_box_.x = 2*kWindowWidth - view_box_.w;
    }
    if (view_box_.y > 2*kWindowHeight - view_box_.h) {
      view_box_.y = 2*kWindowHeight - view_box_.h;
    }

    position_ = Vector2D(view_box_.x, view_box_.y);
  }
}